<?php

class MenuView
{
    private $menuElements;
    
    public function __construct( $menuElements )
    {
        $this->menuElements = $menuElements;
    }
    
    public function DoMenu( $menuItems, $path = '?path=', $indent = '' )
    {
        $html = '';
        
        $html .= "\r\n" . $indent . '<' . $this->menuElements['menuContainer'] . ' class="' . $this->menuElements['menuContainerClass'] . '">' . "\r\n";

        foreach ( $menuItems as $item )
        {
            $page = $path . dmq_urlencode( $item['name'] );
            
            $html .= $indent . '    <' . $this->menuElements['menuItem'] . '><a href="' . $page . '">' . $item['text'] . '</a>';
            
            if ( ! empty( $item['children'] ) )
            {
                $page .= '/';
                
                $html .= $this->DoMenu( $item['children'], $page, $indent . '    ' );
            }
            
            $html .= '</' . $this->menuElements['menuItem'] . '>' . "\r\n";
        }
        
        $html .= $indent . '</' . $this->menuElements['menuContainer'] . '>';
        
        return $html;
    }
}
